package com.huawei.hianalytics.log.e;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Build.VERSION;
import android.text.TextUtils;
import com.huawei.hianalytics.a.b;
import com.huawei.hianalytics.a.d;
import com.huawei.hianalytics.c.c;
import com.huawei.hianalytics.d.a;
import com.huawei.hianalytics.util.f;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import org.json.JSONException;
import org.json.JSONObject;

public class e {
    public static String a(Context context) {
        String b = b(context);
        String str = Build.MODEL;
        String a = f.a();
        String b2 = c.b();
        String str2 = VERSION.RELEASE;
        String h = d.h();
        return String.format(Locale.getDefault(), "%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", new Object[]{"shaSN", b, "model", str, "romVersion", a, "emuiVersion", b2, "osVersion", str2, "countryCode", h});
    }

    public static String a(Context context, boolean z, boolean z2) {
        String format = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
        String str = "";
        str = a.a().c();
        if (TextUtils.isEmpty(str)) {
            str = b.i();
            if (TextUtils.isEmpty(str)) {
                str = c(context);
                b.b(str);
            }
            str = b.a(str);
        } else {
            str = b.a(str);
        }
        return z ? "/Eventid_" + str + "_" + format + "_ALL.zip" : z2 ? "/Crash_" + str + "_" + format + ".zip" : "/Eventid_" + str + "_" + format + ".zip";
    }

    public static String a(String str, String str2) {
        JSONObject jSONObject;
        try {
            jSONObject = new JSONObject(str2);
        } catch (JSONException e) {
            com.huawei.hianalytics.g.b.b("LogStringUtil", "collectErrorLog() MetaData is not a JSON format!");
            jSONObject = new JSONObject();
            try {
                jSONObject.put(str, str2);
            } catch (JSONException e2) {
                com.huawei.hianalytics.g.b.c("LogStringUtil", "checkMetaMsg() An exception occurred in json.put ");
            }
        }
        return jSONObject.toString();
    }

    public static String b(Context context) {
        return b.a(c(context));
    }

    public static String c(Context context) {
        SharedPreferences a = c.a(context, "global_v2");
        String str = "";
        if (a == null) {
            return UUID.randomUUID().toString();
        }
        str = (String) c.b(a, "uuid", "");
        if (!TextUtils.isEmpty(str)) {
            return str;
        }
        str = UUID.randomUUID().toString().replace("-", "");
        a.edit().putString("uuid", str).apply();
        return str;
    }
}
